function arrayToTreeRec(nodes) {
  const map = {};
  const tree = [];
  for (const node of nodes) {
    map[node.id] = { ...node, children: [] };
  }
  for (const node of Object.values(map)) {
    if (node.parentId === null) {
      // 根节点
      tree.push(node);
    } else {
      map[node.parentId].children.push(node);
    }
  }
  return tree;
}
